package com.woniuedu.lecturer.controller;

import com.woniuedu.lecturer.bean.UploadResult;
import com.woniuedu.lecturer.dto.FindByIdTeacherDto;
import com.woniuedu.lecturer.dto.RsFindAllTeacherDto;
import com.woniuedu.lecturer.dto.Teacher;
import com.woniuedu.lecturer.entity.ResponseEntity;
import com.woniuedu.lecturer.entity.TeacherQuery;
import com.woniuedu.lecturer.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author: 王成亮
 * Date: 2022/4/19:9:59
 * Description:教师controller
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Resource
    TeacherService teacherService;

    /**
     * Auther: 王成亮
     * Date: 2022/4/19 10:39
     * Description:分页查询讲师controller
     */
    @PostMapping("/findAllTeacher/{page}/{limit}")
    @ApiOperation(value = "分页查询讲师controller")
    public ResponseEntity<RsFindAllTeacherDto> findAllTeacher(@PathVariable("page")int page,@PathVariable("limit")int limit){
        return teacherService.findAll(page,limit);
    }
    /**
     * Auther: 王成亮
     * Date: 2022/4/19 10:39
     * Description:删除讲师controller
     */
    @GetMapping("/deleteTeacher/{id}")
    @ApiOperation(value = "删除讲师controller")
    public ResponseEntity<com.woniuedu.lecturer.entity.Teacher> deleteTeacherById(@PathVariable("id")String id){
        return teacherService.deleteTeacherById(id);
    }
    /**
     * Auther: 王成亮
     * Date: 2022/4/19 10:39
     * Description:更新讲师controller
     */
    @PostMapping("/updateTeacher")
    @ApiOperation(value = "更新讲师controller")
    public ResponseEntity updateTeacher(@RequestBody com.woniuedu.lecturer.entity.Teacher teacher){
        return teacherService.updateTeacher(teacher);
    }

    /**
     * Auther: 王成亮
     * Date: 2022/4/19 10:39
     * Description:上传讲师头像controller
     */
    @PostMapping("/upload/{id}")
    @ApiOperation(value = "上传讲师头像controller")
    public ResponseEntity<UploadResult> upload(MultipartFile file,@PathVariable("id")String id){
        return teacherService.upload(file,id);
    }

    /**
     * Auther: 王成亮
     * Date: 2022/4/19 10:39
     * Description:新增讲师controller
     */
    @PostMapping("/addTeacher")
    @ApiOperation(value = "新增讲师controller")
    public ResponseEntity<Teacher>  addTeacher(@RequestBody Teacher addTeacherDto){
        return teacherService.addTeacher(addTeacherDto);
    }
    /**
     * Auther: 王成亮
     * Date: 2022/4/19 10:39
     * Description:根据id查询讲师controller
     */
    @GetMapping("/findTeacherById/{id}")
    @ApiOperation(value = "根据id查询讲师controller")
    public ResponseEntity<FindByIdTeacherDto> findTeacherById(@PathVariable("id")String id){
        return teacherService.findTeacherById(id);
    }
    /**
     * Auther: 王成亮
     * Date: 2022/4/19 10:39
     * Description:根据条件查询讲师controller
     */
        @PostMapping("/findTeacherByTeacher/{current}/{limit}")
    @ApiOperation(value = "根据条件查询讲师controller")
    public ResponseEntity findTeacherByTeacher(@PathVariable("current")int current, @PathVariable("limit")int limit, @RequestBody TeacherQuery teacherQuery){
            System.out.println(teacherQuery);
            return teacherService.findTeacherByTeacher(current,limit,teacherQuery);
    }
}
